package com.qkl.qkl.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qkl.qkl.common.Dto;
import com.qkl.qkl.dataBean.AccountCert;
import com.qkl.qkl.dataBean.UserCert;
import com.qkl.qkl.dataBean.UserCommonBean;
import com.tencent.trustsql.sdk.TrustSDK;
import com.tencent.trustsql.sdk.util.SignStrUtil;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.Map;
import java.util.TreeMap;

/**
 * Created by with Intellij IDEA
 * Author : tianhaoyi
 * Date : 2018/7/20
 * Time : 9:56
 */
public class RequestDataUtil {
    //私钥
//    static String prvKey = "2r5KM0GFlyVJaZzyDVh2fCzwNykyjINJDTUFQKgMStw=";
    //公钥
//    static String pubKey = "AttKPLaTisB35xEHTpjxzrMQXj72F7oLJZYfEBqYXZ8Z";


    //设置公共参数
    public static UserCommonBean getUserCommonData(Dto dto) {
        UserCommonBean req = new UserCommonBean();
        String mch_id = "gb2af850d5722c68";
        String product_code = "productA";
        String seq_no = DateUtil.getUUID();
        String user_id = DateUtil.getUUID();
        String user_fullName = "哈哈";
        req.setMch_id(dto.getString("mch_id"));
        req.setProduct_code(dto.getString("product_code"));
        req.setSeq_no(dto.getString("seq_no"));
        req.setType(Conts.USER_REGISTER_TYPE);

        req.setTime_stamp(System.currentTimeMillis());

        return req;
    }

    //注册用户参数
    public static String generateRegisterUserRequest(Dto dto) throws Exception {
        //获取公共参数
        UserCommonBean req = getUserCommonData(dto);

        String pubKey = dto.getString("pubKey");
        String prvKey = dto.getString("prvKey");
        UserCert user = new UserCert();
        user.setUser_id(dto.getString("user_id"));
        user.setUser_fullName(dto.getString("user_fullName"));
        user.setPublic_key(pubKey);
        req.setReq_data(JSONObject.toJSONString(user));

        String signSrc = SignUtil.genSignSrc(req);
        String sign = TrustSDK.signString(prvKey, signSrc.getBytes(), false);
        req.setSign(sign);
        return JSONObject.toJSONString(req);
    }

    //查询用户参数
    public static String generateQueryAllAccountRequest(Dto dto) throws Exception {
        //获取公共参数
        UserCommonBean req = getUserCommonData(dto);

        String prvKey = dto.getString("prvKey");

        AccountCert account = new AccountCert();
        account.setUser_id(dto.getString("user_id"));

        req.setReq_data(JSONObject.toJSONString(account));

        String signSrc = SignUtil.genSignSrc(req);
        String sign = TrustSDK.signString(prvKey, signSrc.getBytes(), false);
        req.setSign(sign);
        return JSONObject.toJSONString(req);
    }

    //创建用户账户参数
    public static String generateRegisterAccountRequest(Dto dto) throws Exception {
        //获取公共参数
        UserCommonBean req = getUserCommonData(dto);

        String pubKey = dto.getString("pubKey");
        String prvKey = dto.getString("prvKey");

        AccountCert account = new AccountCert();
        account.setUser_id(dto.getString("user_id"));
        account.setPublic_key(pubKey);
        req.setReq_data(JSONObject.toJSONString(account));

        String signSrc = SignUtil.genSignSrc(req);
        String sign = TrustSDK.signString(prvKey, signSrc.getBytes(), false);

        req.setSign(sign);
        return JSONObject.toJSONString(req);
    }

    //获取用户账户地址列表参数
    public static String getUserAccountRequest(Dto dto) throws Exception {
        //获取公共参数
        UserCommonBean req = getUserCommonData(dto);

        String prvKey = dto.getString("prvKey");

        UserCert userCert = new UserCert();
        userCert.setUser_id(dto.getString("user_id"));
        userCert.setState(dto.getString("state"));
        userCert.setBegin_time(dto.getString(""));
        userCert.setEnd_time(dto.getString("end_time"));
        if (dto.get("page") != null) {
            userCert.setPage(dto.getInteger("page"));
        }
        if (dto.get("limit") != null) {
            userCert.setLimit(dto.getInteger("limit"));
        }


        req.setReq_data(JSONObject.toJSONString(userCert));

        String signSrc = SignUtil.genSignSrc(req);
        String sign = TrustSDK.signString(prvKey, signSrc.getBytes(), false);

        req.setSign(sign);

        return JSONObject.toJSONString(req);
    }

    //获取用户账户公钥参数
    public static String getUserAccountPubKeyRequest(Dto dto) throws Exception {
        //获取公共参数
        UserCommonBean req = getUserCommonData(dto);

        String prvKey = dto.getString("prvKey");

        AccountCert accountCert = new AccountCert();
        accountCert.setUser_id(dto.getString("user_id"));
        accountCert.setPublic_key(dto.getString("public_key"));


        req.setReq_data(JSONObject.toJSONString(accountCert));

        String signSrc = SignUtil.genSignSrc(req);
        String sign = TrustSDK.signString(prvKey, signSrc.getBytes(), false);

        req.setSign(sign);

        return JSONObject.toJSONString(req);
    }


    //共享信息新增/追加参数
    public static String issAppendRequest(Dto dto) throws Exception {
        String mchId = dto.getString("mch_id");
        String prvKey = dto.getString("prvKey");
        String jsonArr = dto.getString("jsonObject");
        JSONObject jsonObj = JSONObject.parseObject(jsonArr);
        Map<String, Object> paramMap = new TreeMap<String, Object>();
        paramMap.put("version", jsonObj.getString("version"));
        paramMap.put("sign_type", jsonObj.getString("sign_type"));
        paramMap.put("mch_id", mchId);
        if (StringUtils.isNotEmpty(jsonObj.getString("node_id"))) {
            paramMap.put("node_id", jsonObj.getString("node_id"));
        }
        paramMap.put("chain_id", jsonObj.getString("chain_id"));
        paramMap.put("ledger_id", jsonObj.getString("ledger_id"));
        paramMap.put("info_key", jsonObj.getString("info_key"));
        paramMap.put("info_version", jsonObj.getString("info_version"));
        paramMap.put("state", jsonObj.getString("state"));
        paramMap.put("content", jsonObj.getJSONObject("content"));
        paramMap.put("notes", jsonObj.getJSONObject("notes"));
        paramMap.put("commit_time", jsonObj.getString("commit_time"));
        paramMap.put("timestamp", jsonObj.getString("timestamp"));
        paramMap.put("account", TrustSDK.generateAddrByPrvkey(prvKey));
        paramMap.put("public_key", TrustSDK.generatePubkeyByPrvkey(prvKey, true));
        if (dto.containsKey("sign_str")) {
            paramMap.put("sign",TrustSDK.SignRenString(prvKey, Hex.decodeHex(dto.getString("sign_str").toCharArray())));
        }
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }

        return postJson.toJSONString();
    }


    //共享信息查询参数
    public static String issQueryRequest(Dto dto) throws Exception {
//        String mchId = dto.getString("mch_id");
        String prvKey = dto.getString("prvKey");
        String jsonArr = dto.getString("jsonObject");
        JSONObject jsonObj = JSONObject.parseObject(jsonArr);
        Map<String, Object> paramMap = new TreeMap<String, Object>();
        paramMap.put("version", dto.getString("version"));
        paramMap.put("mch_id", dto.getString("mch_id"));
//        paramMap.put("sign_type",  jsonObj.getString("sign_type"));
//        paramMap.put("chain_id", jsonObj.getString("chain_id"));
//        paramMap.put("ledger_id", jsonObj.getString("ledger_id"));
//        paramMap.put("timestamp", jsonObj.getString("timestamp"));
        for (Map.Entry<String, Object> entry : jsonObj.entrySet()) {
            paramMap.put(entry.getKey(), entry.getValue());
        }
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }

        return postJson.toJSONString();
    }

    //资产发行申请参数
    public static String damAssetApplyRequest(Dto dto) throws Exception {
        String prvKey = dto.getString("prvKey");
        Map<String, Object> paramMap = new TreeMap<String, Object>();
        paramMap.put("version", Conts.VERSION);
        paramMap.put("sign_type", Conts.SIGN_TYPE);
        paramMap.put("mch_id", dto.getString("mch_id"));
        if (dto.containsKey("node_id")) {
            paramMap.put("node_id", dto.getString("node_id"));
        }
        paramMap.put("chain_id", dto.getString("chain_id"));
        paramMap.put("ledger_id", dto.getString("ledger_id"));
        if (dto.containsKey("source_id")) {
            paramMap.put("source_id", dto.getString("source_id"));
        }
        paramMap.put("owner_account", dto.getString("owner_account"));
        paramMap.put("asset_type", dto.getString("asset_type"));
        paramMap.put("amount", dto.getString("amount"));
        paramMap.put("unit", dto.getString("unit"));
        paramMap.put("content", JSONObject.parseObject(dto.getString("content")));
        paramMap.put("timestamp", System.currentTimeMillis() / 1000);
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }
        return postJson.toJSONString();
    }

    //资产发行提交参数
    public static String damAssetSubmitRequest(Dto dto) throws Exception {
        String prvKey = dto.getString("prvKey");
        Map<String, Object> paramMap = new TreeMap<String, Object>();
        paramMap.put("version", Conts.VERSION);
        paramMap.put("sign_type", Conts.SIGN_TYPE);
        paramMap.put("mch_id", dto.getString("mch_id"));
        if (dto.containsKey("node_id")) {
            paramMap.put("node_id", dto.getString("node_id"));
        }
        paramMap.put("chain_id", dto.getString("chain_id"));
        paramMap.put("ledger_id", dto.getString("ledger_id"));
        paramMap.put("asset_type", dto.getString("asset_type"));
        paramMap.put("sign_list", JSONArray.parseArray(dto.getString("sign_list")));
        paramMap.put("transaction_id", dto.getString("transaction_id"));
        paramMap.put("asset_id", dto.getString("asset_id"));
        paramMap.put("timestamp", System.currentTimeMillis() / 1000);
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }
        return postJson.toJSONString();
    }

    //资产转让至中间账户申请参数
    public static String damAssetTransferMidApplayRequest(Dto dto) throws Exception {
        String prvKey = dto.getString("prvKey");
        Map<String, Object> paramMap = new TreeMap<String, Object>();
        paramMap.put("version", Conts.VERSION);
        paramMap.put("sign_type", Conts.SIGN_TYPE);
        paramMap.put("mch_id", dto.getString("mch_id"));
        if (dto.containsKey("node_id")) {
            paramMap.put("node_id", dto.getString("node_id"));
        }
        paramMap.put("chain_id", dto.getString("chain_id"));
        paramMap.put("ledger_id", dto.getString("ledger_id"));
        paramMap.put("src_account", dto.getString("src_account"));
        paramMap.put("dst_account", dto.getString("dst_account"));
        if (dto.containsKey("fee_account")) {
            paramMap.put("fee_account", dto.getString("fee_account"));
        }

        paramMap.put("src_asset_id", dto.getString("src_asset_id"));
        paramMap.put("asset_type", dto.getString("asset_type"));
        paramMap.put("amount", dto.getString("amount"));
        if (dto.containsKey("fee_amount")) {
            paramMap.put("fee_amount", dto.getString("fee_amount"));
        }

        if (dto.containsKey("sign_in_date")) {
            paramMap.put("sign_in_date", dto.getString("sign_in_date"));
        }

        if (dto.containsKey("extra_info")) {
            paramMap.put("extra_info", JSONObject.parseObject(dto.getString("extra_info")));
        }

        paramMap.put("timestamp", System.currentTimeMillis() / 1000);
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }
        return postJson.toJSONString();
    }

    //资产转让至中间账户提交参数
    public static String damAssetTransferMidSubmitRequest(Dto dto) throws Exception {
        String prvKey = dto.getString("prvKey");
        Map<String, Object> paramMap = new TreeMap<String, Object>();
        paramMap.put("version", Conts.VERSION);
        paramMap.put("sign_type", Conts.SIGN_TYPE);
        paramMap.put("mch_id", dto.getString("mch_id"));
        if (dto.containsKey("node_id")) {
            paramMap.put("node_id", dto.getString("node_id"));
        }
        paramMap.put("chain_id", dto.getString("chain_id"));
        paramMap.put("ledger_id", dto.getString("ledger_id"));
        paramMap.put("transaction_id", dto.getString("transaction_id"));
        paramMap.put("asset_type", dto.getString("asset_type"));
        //获取待签名串
        String signList = dto.getString("sign_list");
        //将待签名串转成json
        JSONObject signJson = JSONObject.parseObject(signList);

        signJson.put("sign", TrustSDK.SignRenString(prvKey, Hex.decodeHex(signJson.getString("sign_str").toCharArray())));

        paramMap.put("sign_list", signJson.toString());

        paramMap.put("timestamp", System.currentTimeMillis() / 1000);
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }
        return postJson.toJSONString();
    }

    //资产转让签收申请参数
    public static String damAssetSigninApplayRequest(Dto dto) throws Exception {
        String prvKey = dto.getString("prvKey");
        Map<String, Object> paramMap = new TreeMap<String, Object>();
        paramMap.put("version", Conts.VERSION);
        paramMap.put("sign_type", Conts.SIGN_TYPE);
        paramMap.put("mch_id", dto.getString("mch_id"));
        if (dto.containsKey("node_id")) {
            paramMap.put("node_id", dto.getString("node_id"));
        }
        paramMap.put("chain_id", dto.getString("chain_id"));
        paramMap.put("ledger_id", dto.getString("ledger_id"));
        paramMap.put("src_account", dto.getString("src_account"));
        paramMap.put("dst_account", dto.getString("dst_account"));
        if (dto.containsKey("fee_account")) {
            paramMap.put("fee_account", dto.getString("fee_account"));
        }

        paramMap.put("mid_asset_id", dto.getString("mid_asset_id"));
        paramMap.put("asset_type", dto.getString("asset_type"));
        paramMap.put("amount", dto.getString("amount"));
        if (dto.containsKey("fee_amount")) {
            paramMap.put("fee_amount", dto.getString("fee_amount"));
        }
        paramMap.put("extra_info", JSONObject.parseObject(dto.getString("extra_info")));
        paramMap.put("op_code", dto.getString("op_code"));

        paramMap.put("timestamp", System.currentTimeMillis() / 1000);
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }
        return postJson.toJSONString();
    }

    //资产转让申请参数
    public static String damAssetTransferApplayRequest(Dto dto) throws Exception {
        String prvKey = dto.getString("prvKey");
        Map<String, Object> paramMap = new TreeMap<String, Object>();
        paramMap.put("version", Conts.VERSION);
        paramMap.put("sign_type", Conts.SIGN_TYPE);
        paramMap.put("mch_id", dto.getString("mch_id"));
        if (dto.containsKey("node_id")) {
            paramMap.put("node_id", dto.getString("node_id"));
        }
        paramMap.put("chain_id", dto.getString("chain_id"));
        paramMap.put("ledger_id", dto.getString("ledger_id"));
        paramMap.put("src_account", dto.getString("src_account"));
        paramMap.put("dst_account", dto.getString("dst_account"));
        if (dto.containsKey("fee_account")) {
            paramMap.put("fee_account", dto.getString("fee_account"));
        }
        paramMap.put("src_asset_list", dto.getString("src_asset_list"));
        paramMap.put("asset_type", dto.getString("asset_type"));
        paramMap.put("amount", dto.getString("amount"));
        if (dto.containsKey("fee_amount")) {
            paramMap.put("fee_amount", dto.getString("fee_amount"));
        }


        if (dto.containsKey("extra_info")) {
            paramMap.put("extra_info", JSONObject.parseObject(dto.getString("extra_info")));
        }

        paramMap.put("timestamp", System.currentTimeMillis() / 1000);
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }
        return postJson.toJSONString();
    }

    //资产兑付申请参数
    public static String damAssetSettleApplyRequest(Dto dto) throws Exception {
        String prvKey = dto.getString("prvKey");
        Map<String, Object> paramMap = new TreeMap<String, Object>();

        paramMap.put("version", Conts.VERSION);
        paramMap.put("sign_type", Conts.SIGN_TYPE);
        paramMap.put("mch_id", dto.getString("mch_id"));
        if (dto.containsKey("node_id")) {
            paramMap.put("node_id", dto.getString("node_id"));
        }
        paramMap.put("chain_id", dto.getString("chain_id"));
        paramMap.put("ledger_id", dto.getString("ledger_id"));
        paramMap.put("owner_account", dto.getString("owner_account"));
        paramMap.put("src_asset_list", dto.getString("src_asset_list"));
        paramMap.put("asset_type", dto.getString("asset_type"));
        paramMap.put("amount", dto.getString("amount"));

        paramMap.put("timestamp", System.currentTimeMillis() / 1000);
        paramMap.put("extra_info", JSONObject.parseObject(dto.getString("extra_info")));
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }
        return postJson.toJSONString();
    }

    //资产批量查询参数
    public static String damAssetAccountQueryRequest(Dto dto) throws Exception {
        String prvKey = dto.getString("prvKey");
        Map<String, Object> paramMap = new TreeMap<String, Object>();

        paramMap.put("version", Conts.VERSION);
        paramMap.put("sign_type", Conts.SIGN_TYPE);
        paramMap.put("mch_id", dto.getString("mch_id"));
        if (dto.containsKey("node_id")) {
            paramMap.put("node_id", dto.getString("node_id"));
        }
        paramMap.put("chain_id", dto.getString("chain_id"));
        paramMap.put("ledger_id", dto.getString("ledger_id"));
        //这三个参数三选一
        if (dto.containsKey("owner_uid")) {
            paramMap.put("owner_uid", dto.getString("owner_uid"));
        } else if (dto.containsKey("asset_account")) {
            paramMap.put("asset_account", dto.getString("asset_account"));
        } else if (dto.containsKey("asset_id")) {
            paramMap.put("asset_id", dto.getString("asset_id"));
        }

        paramMap.put("state", dto.getString("state"));
        paramMap.put("page_limit", dto.getString("page_limit"));
        paramMap.put("page_no", dto.getString("page_no"));

        paramMap.put("timestamp", System.currentTimeMillis() / 1000);
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }
        return postJson.toJSONString();
    }

    //交易批量查询参数
    public static String damAssetTransQueryRequest(Dto dto) throws Exception {
        String prvKey = dto.getString("prvKey");
        Map<String, Object> paramMap = new TreeMap<String, Object>();

        paramMap.put("version", Conts.VERSION);
        paramMap.put("sign_type", Conts.SIGN_TYPE);
        paramMap.put("mch_id", dto.getString("mch_id"));
        if (dto.containsKey("node_id")) {
            paramMap.put("node_id", dto.getString("node_id"));
        }
        paramMap.put("chain_id", dto.getString("chain_id"));
        paramMap.put("ledger_id", dto.getString("ledger_id"));
        if (dto.containsKey("src_account")) {
            paramMap.put("src_account", dto.getString("src_account"));
        }
        if (dto.containsKey("dst_account")) {
            paramMap.put("dst_account", dto.getString("dst_account"));
        }
        if (dto.containsKey("transaction_id")) {
            paramMap.put("transaction_id", dto.getString("transaction_id"));
        }
        if (dto.containsKey("trans_type")) {
            paramMap.put("trans_type", dto.getString("trans_type"));
        }
        if (dto.containsKey("state")) {
            paramMap.put("state", dto.getString("state"));
        }
        paramMap.put("page_limit", dto.getString("page_limit"));
        paramMap.put("page_no", dto.getString("page_no"));

        if (dto.containsKey("month")) {
            paramMap.put("month", dto.getString("month"));
        }

        paramMap.put("timestamp", System.currentTimeMillis() / 1000);
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }
        return postJson.toJSONString();
    }

    //资产汇总对账参数
    public static String damAssetRecSumQueryRequest(Dto dto) throws Exception {
        String prvKey = dto.getString("prvKey");
        Map<String, Object> paramMap = new TreeMap<String, Object>();

        paramMap.put("version", Conts.VERSION);
        paramMap.put("sign_type", Conts.SIGN_TYPE);
        paramMap.put("mch_id", dto.getString("mch_id"));
        if (dto.containsKey("node_id")) {
            paramMap.put("node_id", dto.getString("node_id"));
        }
        paramMap.put("chain_id", dto.getString("chain_id"));
        paramMap.put("ledger_id", dto.getString("ledger_id"));
        paramMap.put("date", dto.getString("date"));
        paramMap.put("state", JSONObject.parseObject(dto.getString("state")));
        paramMap.put("asset_type", dto.getString("asset_type"));

        paramMap.put("timestamp", System.currentTimeMillis() / 1000);
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }
        return postJson.toJSONString();
    }

    //资产明细对账参数
    public static String damAssetRecDetailQueryRequest(Dto dto) throws Exception {
        String prvKey = dto.getString("prvKey");
        Map<String, Object> paramMap = new TreeMap<String, Object>();

        paramMap.put("version", Conts.VERSION);
        paramMap.put("sign_type", Conts.SIGN_TYPE);
        paramMap.put("mch_id", dto.getString("mch_id"));
        if (dto.containsKey("node_id")) {
            paramMap.put("node_id", dto.getString("node_id"));
        }
        paramMap.put("chain_id", dto.getString("chain_id"));
        paramMap.put("ledger_id", dto.getString("ledger_id"));
        paramMap.put("date", dto.getString("date"));
        paramMap.put("state", JSONObject.parseObject(dto.getString("state")));
        paramMap.put("asset_type", dto.getString("asset_type"));
        paramMap.put("page_limit", dto.getString("page_limit"));
        paramMap.put("page_no", dto.getString("page_no"));
        paramMap.put("timestamp", System.currentTimeMillis() / 1000);
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }
        return postJson.toJSONString();
    }

    //交易汇总对账参数
    public static String damAssetRecTransSumQueryRequest(Dto dto) throws Exception {
        String prvKey = dto.getString("prvKey");
        Map<String, Object> paramMap = new TreeMap<String, Object>();

        paramMap.put("version", Conts.VERSION);
        paramMap.put("sign_type", Conts.SIGN_TYPE);
        paramMap.put("mch_id", dto.getString("mch_id"));
        if (dto.containsKey("node_id")) {
            paramMap.put("node_id", dto.getString("node_id"));
        }
        paramMap.put("chain_id", dto.getString("chain_id"));
        paramMap.put("ledger_id", dto.getString("ledger_id"));
        paramMap.put("date", dto.getString("date"));
        paramMap.put("asset_type", dto.getString("asset_type"));

        paramMap.put("timestamp", System.currentTimeMillis() / 1000);
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }
        return postJson.toJSONString();
    }

    //交易明细对账参数
    public static String damAssetRecTransDetailQueryRequest(Dto dto) throws Exception {
        String prvKey = dto.getString("prvKey");
        Map<String, Object> paramMap = new TreeMap<String, Object>();

        paramMap.put("version", Conts.VERSION);
        paramMap.put("sign_type", Conts.SIGN_TYPE);
        paramMap.put("mch_id", dto.getString("mch_id"));
        if (dto.containsKey("node_id")) {
            paramMap.put("node_id", dto.getString("node_id"));
        }
        paramMap.put("chain_id", dto.getString("chain_id"));
        paramMap.put("ledger_id", dto.getString("ledger_id"));
        paramMap.put("date", dto.getString("date"));
        paramMap.put("trans_type", dto.getString("trans_type"));
        paramMap.put("state", dto.getString("state"));
        paramMap.put("asset_type", dto.getString("asset_type"));
        paramMap.put("page_limit", dto.getString("page_limit"));
        paramMap.put("page_no", dto.getString("page_no"));
        paramMap.put("timestamp", System.currentTimeMillis() / 1000);
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }
        return postJson.toJSONString();
    }

    //资产批量转让至中间账户申请参数
    public static String damAssetMulttransmidApplyRequest(Dto dto) throws Exception {
        String prvKey = dto.getString("prvKey");
        Map<String, Object> paramMap = new TreeMap<String, Object>();

        paramMap.put("version", Conts.VERSION);
        paramMap.put("sign_type", Conts.SIGN_TYPE);
        paramMap.put("mch_id", dto.getString("mch_id"));
        if (dto.containsKey("node_id")) {
            paramMap.put("node_id", dto.getString("node_id"));
        }
        paramMap.put("chain_id", dto.getString("chain_id"));
        paramMap.put("ledger_id", dto.getString("ledger_id"));
        paramMap.put("src_account", dto.getString("src_account"));
        paramMap.put("dst_account", dto.getString("dst_account"));
        if (dto.containsKey("fee_account")) {
            paramMap.put("fee_account", dto.getString("fee_account"));
        }
        paramMap.put("asset_type", dto.getString("asset_type"));
        if (dto.containsKey("extra_info")) {
            paramMap.put("extra_info", JSONObject.parseObject(dto.getString("extra_info")));
        }

        paramMap.put("mult_asset", JSONObject.parseObject(dto.getString("mult_asset")));
        paramMap.put("timestamp", System.currentTimeMillis() / 1000);
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }
        return postJson.toJSONString();
    }

    //资资产批量转让签收申请(转让签收场景)
    public static String damAssetMulsigninApplyRequest(Dto dto) throws Exception {
        String prvKey = dto.getString("prvKey");
        Map<String, Object> paramMap = new TreeMap<String, Object>();

        paramMap.put("version", Conts.VERSION);
        paramMap.put("sign_type", Conts.SIGN_TYPE);
        paramMap.put("mch_id", dto.getString("mch_id"));
        if (dto.containsKey("node_id")) {
            paramMap.put("node_id", dto.getString("node_id"));
        }
        paramMap.put("chain_id", dto.getString("chain_id"));
        paramMap.put("ledger_id", dto.getString("ledger_id"));
        paramMap.put("src_account", dto.getString("src_account"));
        paramMap.put("dst_account", dto.getString("dst_account"));
        if (dto.containsKey("fee_account")) {
            paramMap.put("fee_account", dto.getString("fee_account"));
        }
        paramMap.put("asset_type", dto.getString("asset_type"));
        paramMap.put("total_src_amount", dto.getString("total_src_amount"));

        if (dto.containsKey("total_fee_amount")) {
            paramMap.put("total_fee_amount", dto.getString("total_fee_amount"));
        }
            paramMap.put("extra_info", JSONObject.parseObject(dto.getString("extra_info")));
        paramMap.put("op_code", JSONObject.parseObject(dto.getString("op_code")));
        paramMap.put("timestamp", System.currentTimeMillis() / 1000);
        paramMap.put("mch_sign", TrustSDK.signString(prvKey, SignStrUtil.mapToKeyValueStr(paramMap).getBytes(), false));
        JSONObject postJson = new JSONObject();
        for (String key : paramMap.keySet()) {
            postJson.put(key, paramMap.get(key));
        }
        return postJson.toJSONString();
    }
}
